package com.gupt.youhd.controller;/*
@author name
@data 2023/4/21-14:45
*/

import com.gupt.youhd.common.R;
import com.gupt.youhd.qo.LoginQo;
import com.gupt.youhd.qo.RegisterQo;
import com.gupt.youhd.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;


@RestController
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;


    @PostMapping("/login")    //HttpServletRequest request 要放在方法首位
    public R<Map<String,String>> login(@RequestBody LoginQo qo){

        Map<String,String> map = loginService.login(qo);

        return R.success(map);
      }


    @GetMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        loginService.logout(request);
        return R.success("注销成功");
    }

    /**
     * 忘记密码请求
     * 1获取验证码
     * 2校验验证码
     * 3修改数据库的密码
     */
    @GetMapping("/getCaptcha")
    public R<Map> getCaptcha(String username){
        Map<String, String> map = loginService.getCaptcha(username);
        return R.success(map);
    }

    @GetMapping("/getCaptcha/next")
    public R<String> getCaptchaNext(String uuid,String code){
        loginService.getCaptchaNext(uuid,code);
        return R.success("下一步");
    }

    @PostMapping("/updatePwd")
    public R<String> update(@RequestBody RegisterQo qo){
        int count = loginService.update(qo);
        log.info("修改密码条数：",count);
        return R.success("修改成功");
    }

}





/**
 * 查询商品评价
 *
 * 批量删除
 *
 * 查询待发货
 * 收货
 * 评价
 *
 *添加收货
 *添加评价
 *
 */